package org.rcloud.io.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.model.Picture;
import org.rcloud.io.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2019/3/3.
 */
@RestController
@RequestMapping(value = "/picture")
public class PictureController {
    @Autowired
    private PictureService pictureService;

    @RequestMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public ResultVo add(@RequestBody String params){
        JSONObject object = JSONObject.parseObject(params);
        object.put("id", UUID.randomUUID());
        object.put("createtime",new Date());
        object.put("flag",1);
        Picture picture = JSONObject.parseObject(object.toString(),Picture.class);
        return pictureService.insertSelective(picture);

    }

     /*
    * 修改
    *
    * */

    @RequestMapping(value = "/update", produces = {"application/json;charset=UTF-8"})
    public ResultVo update(@RequestBody String params) {
        Picture picture = JSONObject.parseObject(params, Picture.class);
        return pictureService.updateByPrimaryKey(picture);
    }

    /*
   * 查询
   *
   * */
    @RequestMapping(value = "/select", produces = {"application/json;charset=UTF-8"})
    public ResultVo select(@RequestBody String params) {
        Picture picture = JSONObject.parseObject(params, Picture.class);
        return pictureService.selectByPrimaryKey(picture);
    }

    /*
   * 查询
   *
   * */
    @RequestMapping(value = "/selectByOther", produces = {"application/json;charset=UTF-8"})
    public PageInfo<Picture> selectByOther(@RequestBody JSONObject params) {
        PageInfo<Picture> pageInfo = pictureService.selectByOther(params);
        return pageInfo;

    }

}
